<div class="section" id="sitemaplist">

	<div class="section-title">Quản lý khung lãi xuất</div>
    
    <div class="section-content padding1">
    
    	<form name="frm" id="frm" action="<?php echo $action?>" method="post" enctype="multipart/form-data">
        <input type="hidden" name="nhomtaisanid" value="<?php echo $item['nhomtaisanid']?>">	
            <div class="button right">
                <a class="button save" onclick="save()">Lưu</a>
                <a class="button cancel" href="?route=camdo/nhomtaisan">Bỏ qua</a>    
        	</div>
            <div class="clearer"></div>
        	<div id="error" class="error" style="display:none"></div>
        	<div>   
                
                <p>
                    <label>Tên nhóm tài sản</label><br />
                    <input type="text" name="tennhomtaisan" value="<?php echo $item['tennhomtaisan']?>" class="text" size=60 />
                </p>
                <p>
                    <label>Lãi suất</label><br />
                    <input type="button" class="button" id="btnThemKhungLai" value="Thêm"/>
                    <table style="width:auto">
                    	<thead>
                            <tr>
                                <th>Số tiền >=</th>
                                <th>Lãi xuất áp dụng(%)</th>
                            </tr>
                        </thead>
                        <tbody id="khunglaisuat">
                        </tbody>
                    </table>
                    
                </p>
                
            </div>
            
        </form>
    
    </div>
    
</div>

<script language="javascript">
function LaiSuat()
{
	this.index = 0;
	this.addRow = function(sotien,laisuat)
	{
		var str = "";
		str += '<tr>';
		str += '	<td><input type="text" class="text number" id="sotien-'+this.index+'" name="sotien['+this.index+']" value="'+sotien+'"></td>';
		str += '	<td><input type="text" class="text number" id="laisuat-'+this.index+'" name="laisuat['+this.index+']" value="'+laisuat+'"></td>';
		str += '</tr>';
		$('#khunglaisuat').append(str);
		this.index++;
		numberReady();
	}
}
var lai = new LaiSuat();
$('#btnThemKhungLai').click(function(e) {
    lai.addRow(0,0);
});
<?php if(count($item['laisuat'])){ ?>
	<?php foreach($item['laisuat'] as $obj){ ?>
		lai.addRow("<?php echo $obj->sotien?>","<?php echo $obj->laisuat?>");
	<?php } ?>
<?php } ?>

function save()
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	
	$.post("?route=camdo/nhomtaisan/save", $("#frm").serialize(),
		function(data){
			if(data == "true")
			{
				window.location = "?route=camdo/nhomtaisan";
			}
			else
			{
			
				$('#error').html(data).show('slow');
				$.unblockUI();
				
			}
			
		}
	);
}
</script>
